<template>
    <div class="yinsi">
        <div class="topBox">
            <img class="leftImg" src="../../static/imgs/left_b.png" @click="handleBack" alt="">
            <div class="title">
                {{ $t('assemble.个人资料') }}
            </div>
        </div>

        <div class="userinfoItemList">
            <div class="infoItem">
                <div class="">
                    {{ $t('assemble.用户名称') }}

                </div>
                <div class="right">
                    <input class="inputitem" type="text" v-model="userName">
                    <img class="rightimg" src="../../static/imgs/right_b.png" alt="" srcset="">
                </div>
            </div>
            <div class="infoItem" @click="handlePhone">
                <div class="">
                    {{ $t('assemble.手机号') }}

                </div>
                <div class="right">
                    <div>{{ userInfo.mobile }}</div>
                    <img class="rightimg" src="../../static/imgs/right_b.png" alt="" srcset="">
                </div>
            </div>
            <div class="infoItem" @click="handleEmail">
                <div class="">
                    {{ $t('assemble.邮箱地址') }}

                </div>
                <div class="right">
                    <div>{{ email }}</div>
                    <img class="rightimg" src="../../static/imgs/right_b.png" alt="" srcset="">
                </div>
            </div>

        </div>


        <div class="btn" @click="handleExit">
            {{ $t('assemble.退出登录') }}
        </div>

        <div class="btn btns" @click="handleSave">
            {{ $t('assemble.保存') }}
        </div>



    </div>
</template>
<script>
import { updatenickname } from "../../utils/api"

import jsPDF from 'jspdf';
import { Dialog, Toast } from 'vant';
export default {
    components: {
        Dialog,
        Toast
    },
    data() {
        return {
            content: "",
            lang: 'zh',
            userInfo: {},
            email: "",
            userName: "",
        }
    },
    created() {
        this.$i18n.locale = localStorage.getItem('langtype')
        this.lang = localStorage.getItem('langtype')
        this.userInfo = JSON.parse(localStorage.getItem('userinfo'))
        this.email = JSON.parse(localStorage.getItem('userData')).companyemail
        this.userName = this.userInfo.username
    },
    mounted() {
        // this.getyinsi()
    },
    methods: {
        handleBack() {
            this.$router.back(1)
        },
        handlePhone() {
            this.$router.push({ path: '/pages/mine/updatePhone' })

        },
        handleEmail() {
            this.$router.push({ path: '/pages/mine/updateEmail' })

        },
        async handleSave() {
            let data = {
                nickname: this.userName
            }
            let res = await updatenickname(data)
            if (res.code == 1) {
                Toast(res.msg);
                let userinfo = JSON.parse(localStorage.getItem("userinfo"))
                userinfo.nickname = this.userName
                localStorage.setItem('userinfo', JSON.stringify(userinfo))
                this.$router.back(0)
            } else {
                Toast(res.msg);
            }
        },
        handleExit() {
            Dialog.confirm({
                title: this.$t('assemble.退出'),
                message: this.$t('assemble.您确定要退出吗'),
                confirmButtonText: this.$t('assemble.确定'),
                cancelButtonText: this.$t('assemble.取消'),
            })
                .then(() => {
                    localStorage.removeItem("token")
                    localStorage.removeItem("userinfo")
                    localStorage.removeItem("email")
                    localStorage.setItem("currIndex", 0)
                    Toast(this.$t('assemble.已退出登录'));
                    this.$router.push({ path: '/pages/login/index' })
                })
                .catch(() => {
                });
        },
    },
}
</script>

<style scoped lang="scss">
.inputitem {
    text-align: right;
    border: none;
    outline: none;
}

@media screen and (max-width: 750px) {
    .topBox {
        width: 100%;
        height: 44px;
        // padding: 10px 15px;
        padding-top: 10px;
        position: relative;
        font-family: PingFang SC, PingFang SC;
        font-weight: 600;
        font-size: 16px;
        color: #333333;
        line-height: 19px;
        text-align: left;
        font-style: normal;
        text-transform: none;

        .leftImg {
            width: 24px;
            height: 24px;
            position: absolute;
            top: 10px;
            left: 15px;
        }

        .title {
            width: 100%;
            text-align: center;

        }
    }

    .userinfoItemList {
        .infoItem {
            display: flex;
            align-items: center;
            height: 64px;
            width: 100%;
            padding: 0 15px;
            box-sizing: border-box;
            justify-content: space-between;

            .right {
                display: flex;
                align-items: center;

                .rightimg {
                    width: 24px;
                    height: 24px;
                }
            }
        }
    }

    .btn {
        width: 320px;
        height: 44px;
        background: #F8F8F8;
        border-radius: 100px 100px 100px 100px;
        margin: 0 auto;
        margin-top: 30px;
        font-family: PingFang SC, PingFang SC;
        font-weight: 500;
        font-size: 15px;
        color: #B1B1B1;
        line-height: 44px;
        text-align: center;
        font-style: normal;
        text-transform: none;
    }

    .btns {
        background: #E00000;
        color: #ffffff;
    }

}

@media screen and (min-width: 751px) and (max-width: 1300px) {
    .topBox {
        width: 100%;
        height: 88px;
        // padding: 10px 15px;
        padding-top: 20px;
        position: relative;
        font-family: PingFang SC, PingFang SC;
        font-weight: 600;
        font-size: 25px;
        color: #333333;
        line-height: 19px;
        text-align: left;
        font-style: normal;
        text-transform: none;
        display: flex;
        align-items: center;

        .leftImg {
            width: 48px;
            height: 48px;
            position: absolute;
            top: 40px;
            left: 30px;
        }

        .title {
            width: 100%;
            text-align: center;

        }
    }

    .userinfoItemList {
        .infoItem {
            display: flex;
            align-items: center;
            height: 128px;
            width: 100%;
            padding: 0 30px;
            box-sizing: border-box;
            justify-content: space-between;
            font-size: 24px;

            .right {
                display: flex;
                align-items: center;

                .rightimg {
                    width: 48px;
                    height: 48px;
                }
            }
        }
    }

    .btn {
        width: 75%;
        height: 88px;
        background: #F8F8F8;
        border-radius: 100px 100px 100px 100px;
        margin: 0 auto;
        margin-top: 60px;
        font-family: PingFang SC, PingFang SC;
        font-weight: 500;
        font-size: 22px;
        color: #B1B1B1;
        line-height: 88px;
        text-align: center;
        font-style: normal;
        text-transform: none;
    }

    .btns {
        background: #E00000;
        color: #ffffff;
    }

}
</style>